home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1432.dms / var1432.adf / NDUK-V40.lha / V40 / include / exec / lists.i < prev    next >
Text File  |  1993-10-15  |  4KB  |  173 lines

  1.     IFND    EXEC_LISTS_I
  2. EXEC_LISTS_I    SET    1
  3. **
  4. **    $VER: lists.i 39.1 (28.5.92)
  5. **    Includes Release 40.15
  6. **
  7. **    Definitions and macros for use with Exec lists.  Most of the
  8. **    macros require ownership or locking of the list before use.
  9. **
  10. **    (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  11. **        All Rights Reserved
  12. **
  13.  
  14.     IFND EXEC_NODES_I
  15.     INCLUDE "exec/nodes.i"
  16.     ENDC    ; EXEC_NODES_I
  17.  
  18.  
  19. *---------------------------------------------------------------------
  20.  
  21. *
  22. * Full featured list header
  23. *
  24.    STRUCTURE    LH,0
  25.     APTR    LH_HEAD
  26.     APTR    LH_TAIL
  27.     APTR    LH_TAILPRED
  28.     UBYTE    LH_TYPE
  29.     UBYTE    LH_pad
  30.     LABEL    LH_SIZE ;word aligned
  31.  
  32. *
  33. * Minimal List Header - no type checking (best for most applications)
  34. *
  35.    STRUCTURE    MLH,0
  36.     APTR    MLH_HEAD
  37.     APTR    MLH_TAIL
  38.     APTR    MLH_TAILPRED
  39.     LABEL    MLH_SIZE ;longword aligned
  40.  
  41. *---------------------------------------------------------------------
  42.  
  43. ;Prepare a list header for use
  44. NEWLIST     MACRO   ; list
  45.         MOVE.L  \1,LH_TAILPRED(\1)
  46.         ADDQ.L  #4,\1    ;Get address of LH_TAIL
  47.         CLR.L   (\1)    ;Clear LH_TAIL
  48.         MOVE.L  \1,-(\1)    ;Address of LH_TAIL to LH_HEAD
  49.         ENDM
  50.  
  51. ;Test if list is empty (list address in register)
  52. ;This operation is safe at any time - no list arbitration needed.
  53. TSTLIST     MACRO   ; [list]
  54.         IFGT    NARG-1
  55.            FAIL    !!! TSTLIST - Too many arguments !!!
  56.         ENDC
  57.         IFC     '\1',''
  58.         CMP.L   LH_TAIL+LN_PRED(A0),A0
  59.         ENDC
  60.         IFNC    '\1',''
  61.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  62.         ENDC
  63.         ENDM
  64.  
  65. ;Test if list is empty (from effective address of list)
  66. ;list arbitration required.
  67. TSTLST2     MACRO    ;EA of list,=node
  68.         MOVE.L   \1,\2
  69.         TST.L    (\2)
  70.         ENDM
  71.  
  72. ;Get next in list
  73. SUCC        MACRO   ; node,=succ
  74.         MOVE.L  (\1),\2
  75.         ENDM
  76.  
  77. ;Get previous in list
  78. PRED        MACRO   ; node,=pred
  79.         MOVE.L  LN_PRED(\1),\2
  80.         ENDM
  81.  
  82. ;If empty, branch
  83. IFEMPTY     MACRO   ; list,label
  84.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  85.         BEQ     \2
  86.         ENDM
  87.  
  88. ;If not empty, branch
  89. IFNOTEMPTY  MACRO   ; list,label
  90.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  91.         BNE     \2
  92.         ENDM
  93.  
  94. ;Get next node, test if at end
  95. TSTNODE     MACRO   ; node,=next
  96.         MOVE.L  (\1),\2
  97.         TST.L   (\2)
  98.         ENDM
  99.  
  100. ;Get next, go to exit label if at end
  101. NEXTNODE    MACRO   ; next=next,=current,exit_label ([.s],DX,AX,DISP16)
  102.         MOVE.L  \1,\2
  103.         MOVE.L  (\2),\1
  104.         IFC     '\0',''    ;Check extension
  105.         BEQ     \3
  106.         ENDC
  107.         IFNC    '\0',''
  108.         BEQ.S   \3
  109.         ENDC
  110.         ENDM
  111.  
  112. ;Add to head of list
  113. ADDHEAD     MACRO   ; A0-list(destroyed) A1-node D0-(destroyed)
  114.         MOVE.L  (A0),D0
  115.         MOVE.L  A1,(A0)
  116.         MOVEM.L D0/A0,(A1)
  117.         MOVE.L  D0,A0
  118.         MOVE.L  A1,LN_PRED(A0)
  119.         ENDM
  120.  
  121. ;Add to tail of list
  122. ADDTAIL     MACRO   ; A0-list(destroyed) A1-node D0-(destroyed)
  123.         ADDQ.L  #LH_TAIL,A0
  124.         MOVE.L  LN_PRED(A0),D0
  125.         MOVE.L  A1,LN_PRED(A0)
  126.         EXG     D0,A0
  127.         MOVEM.L D0/A0,(A1)
  128.         MOVE.L  A1,(A0)
  129.         ENDM
  130.  
  131. ;Remove node from whatever list it is in
  132. REMOVE        MACRO   ; A0-(destroyed)  A1-node(destroyed)
  133.         MOVE.L  (A1)+,A0
  134.         MOVE.L  (A1),A1    ; LN_PRED
  135.         MOVE.L  A0,(A1)
  136.         MOVE.L  A1,LN_PRED(A0)
  137.         ENDM
  138.  
  139. ;Remove node from head of list
  140. REMHEAD     MACRO   ; A0-list A1-(destroyed) D0=node
  141.         MOVE.L  (A0),A1
  142.         MOVE.L  (A1),D0
  143.         BEQ.S   REMHEAD\@
  144.         MOVE.L  D0,(A0)
  145.         EXG.L   D0,A1
  146.         MOVE.L  A0,LN_PRED(A1)
  147. REMHEAD\@
  148.         ENDM
  149.  
  150. ;Remove head quickly
  151. ;    Useful when a scratch register is available, and
  152. ;    list is known to contain at least one node.
  153. REMHEADQ    MACRO   ; list,=node,scratchReg-(destroyed)
  154.         MOVE.L  (\1),\2
  155.         MOVE.L  (\2),\3
  156.         MOVE.L  \3,(\1)
  157.         MOVE.L  \1,LN_PRED(\3)
  158.         ENDM
  159.  
  160. ;Remove node from tail of list
  161. REMTAIL     MACRO   ; A0-list A1-(destroyed) D0=node
  162.         MOVE.L  LH_TAIL+LN_PRED(A0),A1
  163.         MOVE.L  LN_PRED(A1),D0
  164.         BEQ.S   REMTAIL\@
  165.         MOVE.L  D0,LH_TAIL+LN_PRED(A0)
  166.         EXG.L   D0,A1
  167.         MOVE.L  A0,(A1)
  168.         ADDQ.L  #4,(A1)
  169. REMTAIL\@
  170.         ENDM
  171.  
  172.     ENDC    ; EXEC_LISTS_I
  173.